set mem 500m
set more off
cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\data"
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/data/"
use 20140308_money_d1.dta, clear

cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\output"
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/output/"
log using balance.smcl, replace

/*****************************************APPENDIX 5A Balance Table of Domestic Firms***********************************************/
keep if reg_year>2000
#delimit;
preserve;
set more off;
foreach x in sector2 gdp pop roads tel_cap email_dich iz region city distance reg_year reg_time labor_est equity_est JS LLC private SOE lurc bribe_size bureaucratic_rents
bureaucratic_time negotiate_tax c4_2010 connection household inspections performance weighted service_delivered sub7 sub3 {;
ttest `x' if FDI==0, by(treatment);
scalar define t_mean_`x'= r(mu_1);
scalar define c_mean_`x'= r(mu_2);
scalar define t_sd_`x'= r(sd_1);
scalar define c_sd_`x'= r(sd_2);
scalar define p_`x'=r(p);
scalar define t_`x'=r(t);
};

collapse pci_id;

#delimit;
set more off;


foreach x in sector2 gdp pop roads tel_cap email_dich iz region city distance reg_year reg_time labor_est equity_est JS LLC private SOE lurc bribe_size bureaucratic_rents
bureaucratic_time negotiate_tax c4_2010 connection household inspections performance weighted service_delivered sub7 sub3 {;
generate t_mean_`x'= t_mean_`x';
generate c_mean_`x'= c_mean_`x';
generate t_sd_`x'= t_sd_`x';
generate c_sd_`x'= c_sd_`x';
generate p_`x'=p_`x';
generate t_`x'=t_`x';
};

#delimit;
drop pci_id;
generate id=_n;
reshape long t_mean_ t_sd_ c_mean_ c_sd_ p_ t_, i(id) j(var) string;
drop if t_mean==.;
replace id=_n;
save ttest_domestic.dta, replace;
outsheet using "ttest_domestic", comma replace;
restore;

/*****************************************APPENDIX 5B Balance Table of Foreign Firms***********************************************/

preserve;
#delimit;
scalar drop _all;
set more off;
foreach x in sector2 gdp pop roads tel_cap iz region city distance reg_year reg_time labor_est equity_est jv fully_owned lurc bribe_size
bureaucratic_time c3 inspections performance weighted service_delivered sub7 sub3
{;

ttest `x' if FDI==1, by(treatment);
scalar define t_mean_`x'= r(mu_1);
scalar define c_mean_`x'= r(mu_2);
scalar define t_sd_`x'= r(sd_1);
scalar define c_sd_`x'= r(sd_2);
scalar define p_`x'=r(p);
scalar define t_`x'=r(t);
};

collapse pci_id;

#delimit;
set more off;
foreach x in sector2 gdp pop roads tel_cap iz region city distance reg_year reg_time labor_est equity_est jv fully_owned lurc bribe_size
bureaucratic_time c3 inspections performance weighted service_delivered sub7 sub3
{;
generate t_mean_`x'= t_mean_`x';
generate c_mean_`x'= c_mean_`x';
generate t_sd_`x'= t_sd_`x';
generate c_sd_`x'= c_sd_`x';
generate p_`x'=p_`x';
generate t_`x'=t_`x';
};

#delimit;
drop pci_id;
generate id=_n;
reshape long t_mean_ t_sd_ c_mean_ c_sd_ p_ t_, i(id) j(var) string;
drop if t_mean==.;
replace id=_n;
save ttest_FDI.dta, replace;
outsheet using "ttest_FDI", comma replace;
restore;


/*****************************************APPENDIX 5C Multiple Regression Balance***********************************************/

#delimit;
preserve;
set more off;
xi: dprobit treatment labor_est equity_est sector2 iz  private LLC time  i.year if FDI==0 , cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all) replace;
xi: dprobit treatment labor_est equity_est sector2 iz  fully_owned time  i.year if FDI==1, cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all);
xi: dprobit treatment labor_est equity_est sector2 iz  private LLC time distance region city roads tel_cap gdp i.year if FDI==0 , cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all);
xi: dprobit treatment labor_est equity_est sector2 iz  fully_owned time  distance region city roads tel_cap gdp i.year if FDI==1, cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all);
xi: dprobit treatment labor_est equity_est sector2 iz  private LLC time distance region city roads tel_cap gdp i.year weighted sub5 if FDI==0 , cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all);
xi: dprobit treatment labor_est equity_est sector2 iz  fully_owned time  distance region city roads tel_cap gdp i.year weighted sub5 if FDI==1, cluster(pci_id);
outreg2 using balance, bdec(3) pvalue e(all) excel;
restore;
log close;

cap cd "C:\Users\ejm5\Dropbox\Rents_Asunder\AJPS_ReplicationFiles\do";
cap cd "/Users/dimitargueorguiev/Dropbox/Rents_Asunder/AJPS_ReplicationFiles/do/";
